/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OpretKundeGUI.java
 *
 * Created on Nov 17, 2011, 8:25:09 AM
 */
package GUILayer;

import ControlLayer.CtrCustomer;
import ControlLayer.CtrCustomerGroup;
import DBLayer.DBCustomer;
import ModelLayer.Customer;
import ModelLayer.CustomerGroup;
import javax.swing.UIManager;

/**
 *
 * @author R3l4X
 */
public class OpretKundeGUI extends javax.swing.JFrame {

    /** Creates new form OpretKundeGUI */
    public OpretKundeGUI() {
        initComponents();
        this.setVisible(true);
        
        
 
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        btnKundeOpretSaveBTN = new javax.swing.JButton();
        btnKundeOpretAnnullere = new javax.swing.JButton();
        lblKundeOpretNavn = new javax.swing.JLabel();
        txtOpretKundeFname = new javax.swing.JTextField();
        txtOpretKundeLname = new javax.swing.JTextField();
        lblKundeOpretEfterNavn = new javax.swing.JLabel();
        txtOpretKundeAdresse = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtOpretKundeZip = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtOpretKundeCity = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtOpretKundePhone = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtOpretKundeEmail = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtOpretKundeDiscount = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        chkPrivat = new javax.swing.JCheckBox();
        chkErhverv = new javax.swing.JCheckBox();
        lblOpretKundeCvr = new javax.swing.JLabel();
        txtOpretKundeCVR = new javax.swing.JTextField();
        lblOpretKundeKredit = new javax.swing.JLabel();
        txtOpretKundeKredit = new javax.swing.JTextField();
        lblOpretKundeBeskrivelse = new javax.swing.JLabel();
        txtOpretKundeBeskrivelse = new javax.swing.JTextField();
        lblOpretKundelabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Opret Kunde");

        btnKundeOpretSaveBTN.setText("Gem");
        btnKundeOpretSaveBTN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKundeOpretSaveBTNActionPerformed(evt);
            }
        });

        btnKundeOpretAnnullere.setText("Annuller");
        btnKundeOpretAnnullere.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKundeOpretAnnullereActionPerformed(evt);
            }
        });

        lblKundeOpretNavn.setText("Navn");

        lblKundeOpretEfterNavn.setText("Efternavn");

        jLabel3.setText("Adresse");

        txtOpretKundeZip.setMinimumSize(new java.awt.Dimension(5, 20));

        jLabel4.setText("Post Nummer");

        jLabel5.setText("By");

        jLabel6.setText("Telefon");

        jLabel7.setText("Email");

        jLabel8.setText("Rabat");

        jLabel1.setText("Kunde Gruppe");

        buttonGroup1.add(chkPrivat);
        chkPrivat.setText("Privat");
        chkPrivat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkPrivatActionPerformed(evt);
            }
        });

        buttonGroup1.add(chkErhverv);
        chkErhverv.setText("Erhverv");
        chkErhverv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkErhvervActionPerformed(evt);
            }
        });

        lblOpretKundeCvr.setText("CVR");

        lblOpretKundeKredit.setText("Kredit");

        lblOpretKundeBeskrivelse.setText("Beskrivelse");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(lblKundeOpretEfterNavn, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(lblKundeOpretNavn))
                            .addComponent(jLabel4)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1)
                            .addComponent(lblOpretKundeBeskrivelse)
                            .addComponent(lblOpretKundeCvr)
                            .addComponent(lblOpretKundeKredit))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chkPrivat)
                            .addComponent(chkErhverv)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtOpretKundeEmail, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundePhone, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeCity, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeLname, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeFname, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeAdresse, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeDiscount, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtOpretKundeZip, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(214, 214, 214))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(txtOpretKundeBeskrivelse, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeCVR, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                                    .addComponent(txtOpretKundeKredit, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
                                .addGap(214, 214, 214))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblOpretKundelabel)
                        .addContainerGap(450, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnKundeOpretSaveBTN)
                        .addGap(10, 10, 10)
                        .addComponent(btnKundeOpretAnnullere)
                        .addContainerGap(316, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblKundeOpretNavn)
                    .addComponent(txtOpretKundeFname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblKundeOpretEfterNavn)
                    .addComponent(txtOpretKundeLname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtOpretKundeAdresse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtOpretKundeZip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtOpretKundeCity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtOpretKundePhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtOpretKundeEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtOpretKundeDiscount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(chkPrivat))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chkErhverv)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtOpretKundeKredit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblOpretKundeKredit))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtOpretKundeCVR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblOpretKundeCvr))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblOpretKundeBeskrivelse)
                    .addComponent(txtOpretKundeBeskrivelse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(24, 24, 24)
                .addComponent(lblOpretKundelabel)
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnKundeOpretAnnullere)
                    .addComponent(btnKundeOpretSaveBTN))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnKundeOpretAnnullereActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKundeOpretAnnullereActionPerformed
     // TODO add your handling code here:
         
      setVisible(false);
      
      
    }//GEN-LAST:event_btnKundeOpretAnnullereActionPerformed

    private void chkPrivatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPrivatActionPerformed
        
        custGroup = new CustomerGroup();       
       
        if(chkPrivat.isSelected())
        {
            custGroup.setType(false);
            
            lblOpretKundeCvr.setEnabled(false);
            txtOpretKundeCVR.setText("0");
            txtOpretKundeKredit.setText("0");
            lblOpretKundeKredit.setEnabled(false);
            lblOpretKundeBeskrivelse.setEnabled(false);
            txtOpretKundeBeskrivelse.setText("Privat");
            
        }
       
    }//GEN-LAST:event_chkPrivatActionPerformed

    private void chkErhvervActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkErhvervActionPerformed

        custGroup = new CustomerGroup();
        
        if (chkErhverv.isSelected())
        {
        custGroup.setType(true);
        lblOpretKundeCvr.setEnabled(true);
        txtOpretKundeCVR.setEnabled(true);
        txtOpretKundeKredit.setEnabled(true);
        lblOpretKundeKredit.setEnabled(true);
        lblOpretKundeBeskrivelse.setEnabled(true);
        txtOpretKundeBeskrivelse.setEnabled(true);
        }

    }//GEN-LAST:event_chkErhvervActionPerformed

    private void btnKundeOpretSaveBTNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKundeOpretSaveBTNActionPerformed

//        try{
        
        CtrCustomer ctrCust = new CtrCustomer();
        CtrCustomerGroup ctrCustG = new CtrCustomerGroup();

        Customer custObj = new Customer();
        CustomerGroup custgrupObj = new CustomerGroup();
        
        custObj.setFname(txtOpretKundeFname.getText());
        custObj.setLname(txtOpretKundeLname.getText());
        custObj.setAddress(txtOpretKundeAdresse.getText());
        custObj.setZipCode(Integer.valueOf(txtOpretKundeZip.getText()));
        custObj.setCity(txtOpretKundeCity.getText());
        custObj.setPhoneNo(Integer.valueOf(txtOpretKundePhone.getText()));
        custObj.setEmail(txtOpretKundeEmail.getText());
        custObj.setDiscount(Double.valueOf(txtOpretKundeDiscount.getText()));
        
      
        if(chkPrivat.isSelected())
        {
        custgrupObj.setType(custGroup.getType());
        
        custgrupObj.setCvr(0);
        custgrupObj.setCredit(0);
        custgrupObj.setDescription("Privat");
        }
        
        if(chkPrivat.isSelected())
        {
        custgrupObj.setType(custGroup.getType());
        
        custgrupObj.setCvr(Integer.valueOf(txtOpretKundeCVR.getText()));
        custgrupObj.setCredit(Double.valueOf(txtOpretKundeKredit.getText()));
        custgrupObj.setDescription(txtOpretKundeBeskrivelse.getText());
     }
       
        
            
        ctrCustG.NewCtrCustomerGroup(custgrupObj);
        ctrCust.NewCustomer(custObj);
        lblOpretKundelabel.setText("Kunden er Oprettet med følgende ID : " + ctrCust.getMaxID());
            
    
//       catch(Exception e)
//               {
//                   lblOpretKundelabel.setText("Fejl");
//                   
//               }

    }//GEN-LAST:event_btnKundeOpretSaveBTNActionPerformed

 
            
            
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
    

        
        
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OpretKundeGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OpretKundeGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OpretKundeGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OpretKundeGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new OpretKundeGUI().setVisible(true);
            }
        });
    
    
    
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnKundeOpretAnnullere;
    private javax.swing.JButton btnKundeOpretSaveBTN;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox chkErhverv;
    private javax.swing.JCheckBox chkPrivat;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel lblKundeOpretEfterNavn;
    private javax.swing.JLabel lblKundeOpretNavn;
    private javax.swing.JLabel lblOpretKundeBeskrivelse;
    private javax.swing.JLabel lblOpretKundeCvr;
    private javax.swing.JLabel lblOpretKundeKredit;
    private javax.swing.JLabel lblOpretKundelabel;
    private javax.swing.JTextField txtOpretKundeAdresse;
    private javax.swing.JTextField txtOpretKundeBeskrivelse;
    private javax.swing.JTextField txtOpretKundeCVR;
    private javax.swing.JTextField txtOpretKundeCity;
    private javax.swing.JTextField txtOpretKundeDiscount;
    private javax.swing.JTextField txtOpretKundeEmail;
    private javax.swing.JTextField txtOpretKundeFname;
    private javax.swing.JTextField txtOpretKundeKredit;
    private javax.swing.JTextField txtOpretKundeLname;
    private javax.swing.JTextField txtOpretKundePhone;
    private javax.swing.JTextField txtOpretKundeZip;
    // End of variables declaration//GEN-END:variables

    private CustomerGroup custGroup;
}
